package com.itboye.eweilisten.util.widget;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.adapter.OldAdapter;
import com.itboye.eweilisten.model.OldBean;
import com.itboye.eweilisten.util.loadingutil.MAlert;
import com.itboye.eweilisten.util.popwindow.BaseDialogFragment;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by itboye on 2017/3/10.
 */

public class SexDialogs extends BaseDialogFragment {

    OldAdapter oldAdapter;
    List<OldBean> old = new ArrayList<>();
    MyListView guigeContainer;
    String sex[] = {"男", "女"};
    int sichat;
    TextView okchongzhi;
    TextView tvdialogTitle;
    int i;
    String name;

    public SexDialogs() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return LayoutInflater.from(getContext()).inflate(
                R.layout.dialog_xuexiao, null);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);
        onDidlog();
        tvdialogTitle.setText("请选择性别");
    }

    public void onDidlog() {
        old.clear();
        for (i = 0; i < sex.length; i++) {
            OldBean data = new OldBean();
            data.setName(sex[i]);
            old.add(data);

        }
        oldAdapter = new OldAdapter(getContext(), old);
        guigeContainer.setAdapter(oldAdapter);
        guigeContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                oldAdapter.clearSelection(position);
                oldAdapter.notifyDataSetChanged();
                name = old.get(position).getName();
            }
        });
        okchongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeDialog();
                MAlert.alert(name+"");
                try {
                    if (name == null) {
                        MAlert.alert("还未选择");
                    } else {
                        MAlert.alert(name+"sdgwetwe");
                    }

                } catch (Exception e) {
                }


            }
        });
    }

    /***
     * 关闭弹框
     */
    public void closeDialog() {

        View v = getView().findViewById(R.id.okchongzhi);
        ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationY",
                0, v.getHeight()).setDuration(300);
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator arg0) {
            }

            @Override
            public void onAnimationRepeat(Animator arg0) {
            }

            @Override
            public void onAnimationEnd(Animator arg0) {
                dismiss();
            }

            @Override
            public void onAnimationCancel(Animator arg0) {
                dismiss();
            }
        });
        animator.start();
    }
}
